package views.swing;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import models.services.ServicioReportes;
import java.util.HashMap;
import java.util.List;
import models.services.ServicioColonias;
import models.entities.Colonia;

public class ReporteXColonia extends JPanel implements ActionListener, ItemListener{
	private JComboBox comboStatus=new JComboBox(new String[]{"Ambos", "Aceptado", "Rechazado"});
	private JComboBox comboColonias=new JComboBox();
	
	private JButton botonAceptar=new JButton("Aceptar");
	private JButton botonCancelar=new JButton("Cancelar");
	
	public ReporteXColonia(){
		setLayout(new CuestionarioLayout());
		
		comboStatus.addItemListener(this);
		comboColonias.addItem("Todas");
		comboColonias.setEnabled(false);
		
		List<Colonia> colonias=new ServicioColonias().obtenerListaDeColonias();
		for(int k=0; k<colonias.size(); k++){
			comboColonias.addItem(colonias.get(k));
		}
	
		add(new JLabel("Status"), "label");
		add(comboStatus, "field");
		
		add(new JLabel("Colonia"), "label");
		add(comboColonias, "field");
		
		botonAceptar.addActionListener(this);
		botonCancelar.addActionListener(this);

		add(botonAceptar, "label");
		add(botonCancelar, "field");
	}
	
	public void actionPerformed(ActionEvent evt){
		Object origen=evt.getSource();
		if(origen==botonAceptar){
			HashMap variables=new HashMap();
			
			if(comboStatus.getSelectedIndex()==0){
				new ServicioReportes().showReport("Si y no totales.jrxml", variables);
			}else{
				if(comboStatus.getSelectedIndex()==1){
					if(comboColonias.getSelectedIndex()==0){
						new ServicioReportes().showReport("Total aceptaron por colonias.jrxml", variables);
					}else{
						variables.put("id", (comboColonias.getSelectedIndex()+""));
						new ServicioReportes().showReport("Total aceptaron por colonia especifica.jrxmll", variables);
					}
				}else{
					if(comboColonias.getSelectedIndex()==0){
						new ServicioReportes().showReport("Total rechazaron por colonias.jrxml", variables);
					}else{
						variables.put("id", (comboColonias.getSelectedIndex()+""));
						new ServicioReportes().showReport("Total rechazaron por colonia especifica.jrxmll", variables);
					}
				}
			}
		}
	}
	
	public void itemStateChanged(ItemEvent evt){
		comboColonias.setEnabled(comboStatus.getSelectedIndex()!=0);
	}
	
	public static void main(String[] args){
		JFrame ventana=new JFrame("Reporte total por colonia");
		ventana.setContentPane(new ReporteXColonia());
		ventana.pack();
		ventana.setVisible(true);
	}
}
